home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18349 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: ix.netcom.com!news
  2. From: Bradd W. Szonye <bradds@ix.netcom.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: RE: cout and colors; help
  5. Date: 19 Apr 1996 09:56:20 GMT
  6. Organization: Netcom
  7. Message-ID: <01bb2dd6.c0293d40$c6c2b7c7@Zany.localhost>
  8. References: <4k9ut6$q8_001@basmith1.iquest.net>
  9. NNTP-Posting-Host: det-mi6-06.ix.netcom.com
  10. X-NETCOM-Date: Fri Apr 19  4:56:20 AM CDT 1996
  11. X-Newsreader: Microsoft Internet News
  12.  
  13.  
  14. On Sunday, April 07, 1996, Brian Smith wrote...
  15. > I'm new to C++, using Borland Turbo C++ for DOS version 3.0.
  16. > I wrote a small program that used different text colors, and all my
  17. screen 
  18. > output was with putch() or cprintf(). When I tried to use cout, I lost
  19. the 
  20. > ability to set the colors with textcolor(). Surely there's a way to use
  21. cout, 
  22. > with it's much simpler syntax, and still have control over colors, but I
  23. can't 
  24. > find it, either in the manual or the on-line help.
  25. > Any assistance w/b greatly appreciated.
  26. > Brian Smith
  27. Okay, I'm a little rusty with this, but I might be able to help.
  28. You want to define a custom manipulator. (Like cout << width(5) << x <<
  29. endl;).
  30.  
  31. They're easy to write if you don't want it to take a parameter:
  32.  
  33. ostream& blue(ostream& s)
  34. {
  35.     s.flush();  // make sure text so far is written
  36.     textcolor(BLUE);  // usual command to change color
  37. }
  38.  
  39. You can do the same for red, green, etc.
  40.  
  41. To write "cout << color(BLUE) << x << endl;" is a little trickier, but it
  42. can be done. I don't remember how off the top of my head, but you can find
  43. the technique in tutorials that describe either "iostream manipulators" or
  44. the header "iomanip.h"
  45.  
  46.  
  47.